/*
 * table_Operand.c
 *
 *  Created on: 2012/06/29
 *      Author: guanxiaoying
 */
#include "../../parser/coredef.h"
#include "../table.h"
typedef struct _OPERANDINFO
{
	U2		kind;		/* 2 */
	AST		astParam;				/* 7 */
} OPERANDINFO, *POPERANDINFO;

#define TableSize  (sizeof(OPERANDINFO ))
#define TableType  POPERANDINFO
#define stTable stOperandManager.memoryBlocks
#define maxTable stOperandManager.maxRecordNum
#define  maxNumPerBlk  (stOperandManager.astMaxNum_Block)

static TABLEMANAGER stOperandManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stOperandManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stOperandManager, resetListener,  index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}
static BOOL ClearTable( VOID )
{
	return Clear_Com( &stOperandManager );
}
static BOOL ResetTable( VOID )
{
	return Reset_Com( &stOperandManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stOperandManager, astReqArg, resetListener );
}
static AST getMaxLineNum( VOID ){
	return maxTable;
}
/* give up the way that defining get/set function pointer in the struct,
 * because of memory volume.
 */
static U2  getOperandKind( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->kind;
}
/* set method */
static U2  setOperandKind( AST index, U2 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->kind = value;
}
//	IDX_TYPEDEFINFO
static AST  getParameter( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astParam;
}
/* set method */
static AST  setParameter( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->astParam = value;
}

const OPERAND_ACCESS stOperandAccess =
{
		//		BOOL (*clear)( VOID );
				ClearTable,
		//		BOOL (*reset)( VOID );
				ResetTable,
		//		BOOL (*alloc)( AST );
				AllocTable,
				getMaxLineNum,
		{
				getOperandKind,
				setOperandKind
		},
		{
				getParameter,
				setParameter
		}
};
/* end of file */


